﻿using System;
using System.Collections.Generic;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Text;
using iBuproModel;
using iBuproModel.Repositories;
using iBuproModel.Repositories.Classes;
using iBuproModel.Repositories.Interfaces;

namespace IBuproModel.Tests
{
    class InitTest
    {

        private UserRepository users = new UserRepository();
        ProjectRepository projects = new ProjectRepository();
        RoleRepository roles = new RoleRepository();
        StudentPlanRepository plans = new StudentPlanRepository();
        StudentFieldRepository fields = new StudentFieldRepository();
        SubjectRepository subjects = new SubjectRepository();

        public InitTest()
        {
        }



        public Project GetProjectOnly(User u)
        {
            Project project = new Project();
            project.Name = "";
            project.Detail = "";
            project.Created = DateTime.Now;
            project.Shortcut = "";
            project.MemberCount = 0;
            project.Principal = u;
            return project;
        }


        
        public User GetUser()
        {
            User user = new User();
            user.Username = "aaa";
            user.FirstName = "";
            user.LastName = "";
            user.Password = "";
            user.Salt = "";
            user.Email = "";


            user.Projects.Add(GetProjectOnly(user));
            user.Projects.Add(GetProjectOnly(user));
            
            User principal = new User();
            Department dept = new Department();
            dept.DepartmentPrincipal.Add(principal);
            

            users.Add(user);
            users.SaveChanges();
            return user;

        }

        public StudentField GetStudentField()
        {

            StudentField field = new StudentField();
            field.Name = "";
            field.Shortcut = "";
            field.Visible = true;
            
            field.Subjects.Add(GetSubjectOnly());
            field.Subjects.Add(GetSubjectOnly());

            fields.Add(field);
            fields.SaveChanges();
            return field;

        }

        public StudentField GetStudentFieldOnly()
        {

            StudentField field = new StudentField();
            field.Name = "";
            field.Shortcut = "";
            field.Visible = true;

            field.Subjects.Add(GetSubjectOnly());
            field.Subjects.Add(GetSubjectOnly());
            return field;

        }

        public StudentPlan GetStudentPlan()
        {
            StudentPlan plan = new StudentPlan();
            plan.Name = "";
            plan.Shortcut = "";

            plan.Subjects.Add(GetSubjectOnly());
            plan.Subjects.Add(GetSubjectOnly());
            plan.StudentFields.Add(GetStudentFieldOnly());
            plan.StudentFields.Add(GetStudentFieldOnly());

            plans.Add(plan);
            plans.SaveChanges();
            return plan;
        }

        public Subject GetSubjectOnly()
        {
            Subject subject = new Subject();
            subject.Name = "";
            subject.Visible = true;
            subject.Shortcut = "";
            return subject;
        }


        public Subject GetSubject()
        {
            Subject subject = new Subject();
            subject.Name = "";
            subject.Visible = true;
            subject.Shortcut = "";

            subjects.Add(subject);
            subjects.SaveChanges();
            return subject;
        }


    }
}
